#include<iostream>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>
using namespace std;
#define SIZE 20
int main()
{
  pid_t id = fork();
  if(id == 0)
  {
    //child
    char* const _envp[SIZE] = {
      (char*)"HJ=1122334455",
      nullptr
    };
    char* const _argv[SIZE] = {
      (char*)"ls",
      (char*)"-l",
      nullptr
    };
    //execl("/usr/bin/ls","ls","-l",nullptr);//l理解为列表的意思
    //execv("/usr/bin/ls", _argv);//v理解为数组的意思
    //execlp("ls","ls", "-l", "-a", nullptr);
    //execvp("ls",_argv);
    execle("/usr/bin/ls", "ls", "-l", "-a", nullptr, _envp);
    exit(1);
  }
  else
  {
    //father
    int status = 0;
    pid_t ret = waitpid(id, &status, 0);
    if(ret > 0)
    cout << "进程退出码" << WEXITSTATUS(status) << endl;
  }
  return 0;
}
